﻿
@{
    Layout = null;
}

<link href="~/libs/layui-v2.9.21/layui/css/layui.css" rel="stylesheet" />

<form class="layui-form" action="">
	<input type="hidden" name="id" id="id" class="layui-input" />
	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">出库通知</label>
			<div class="layui-input-wrap layui-input-inline">
				<input type="text" id="notices" name="notices" lay-verify="required" placeholder="请输入出库通知" class="layui-input">
			</div>
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">商品编码</label>
			<div class="layui-input-inline layui-input-wrap">
				<input type="text" id="productCode" name="productCode" lay-verify="required" placeholder="请输入商品编码" class="layui-input">
			</div>
			<div class="layui-form-mid">
				<input type="checkbox" lay-skin="switch" lay-filter="switchTest">自动生成
			</div>
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">商品名称</label>
			<div class="layui-input-wrap layui-input-inline">
				<input type="text" id="productName" name="productName" lay-verify="required" placeholder="请输入商品名称" class="layui-input">
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">客户订单号</label>
			<div class="layui-input-wrap layui-input-inline">
				<input type="text" id="productNum" name="productNum" lay-verify="required" placeholder="请输入客户订单号" class="layui-input">
			</div>
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">数量</label>
			<div class="layui-input-wrap layui-input-inline">
				<input type="text" id="takenOffNum" name="takenOffNum" lay-verify="required" placeholder="请输入数量" class="layui-input">
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">单位</label>
			<div class="layui-input-wrap layui-input-inline">
				<select id="unit" name="unit">
					<option value="">请选择</option>
					<option value="个">个</option>
					<option value="听">听</option>
				</select>
			</div>
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">基本单位数量</label>
			<div class="layui-input-wrap layui-input-inline">
				<input type="text" id="unitNum" name="unitNum" lay-verify="required" placeholder="请输入基本单位数量" class="layui-input">
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">基本单位</label>
			<div class="layui-input-wrap layui-input-inline">
				<input type="text" id="unitCode" name="unitCode" lay-verify="required" placeholder="请输入基本单位" class="layui-input">
			</div>
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">生产日期</label>
			<div class="layui-input-wrap layui-input-inline">
				<input type="date" id="productData" name="productData" lay-verify="required" placeholder="请选择生产日期" class="layui-input">
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">货主</label>
			<div class="layui-input-wrap layui-input-inline">
				<input type="text" id="takenOffStatus" name="takenOffStatus" lay-verify="required" placeholder="请输入货主" class="layui-input">
			</div>
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">托盘</label>
			<div class="layui-input-wrap layui-input-inline">
				<input type="text" id="tray" name="tray" lay-verify="required" placeholder="请输入托盘" class="layui-input">
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">任务接受人</label>
			<div class="layui-input-wrap layui-input-inline">
				<input type="text" id="taskPeo" name="taskPeo" lay-verify="required" placeholder="请输入基本单位" class="layui-input">
			</div>
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">仓位</label>
			<div class="layui-input-wrap layui-input-inline">
				<select id="positions" name="positions">
					<option value="">请选择</option>
					<option value="普通仓位">普通仓位</option>
					<option value="特殊仓位">特殊仓位</option>
				</select>
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">下架状态</label>
			<div class="layui-input-wrap layui-input-inline">
				<select id="takenStatus" name="takenStatus">
					<option value="">请选择</option>
					<option value="1">未下架</option>
					<option value="2">已下架</option>
				</select>
			</div>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">备注</label>
		<div class="layui-input-block">
			<textarea id="result" name="result" lay-verify="required" placeholder="请输入备注" class="layui-input"></textarea>
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-input-block">
			<button type="submit" class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
			<button type="reset" class="layui-btn layui-btn-primary">重置</button>
		</div>
	</div>
</form>

<script src="~/libs/layui-v2.9.21/layui/layui.js"></script>
<script src="~/libs/jquery/jquery.js"></script>

<script>
	function GetByiddatas(){
		  $.ajax({
			  url:'/Puff/GetByTakens',
			  type:'get',
			  data:{id:@ViewBag.id},
			  dataType:'json',
			  success:function(res){
				  console.log(res.data)
				  $("#id").val(res.data.id)
				  $("#notices").val(res.data.notices)
				  $("#productCode").val(res.data.productCode)
				  $("#productName").val(res.data.productName)
				  $("#productNum").val(res.data.productNum)
				  $("#takenOffNum").val(res.data.takenOffNum)
				  $("#unit").val(res.data.unit)
				  $("#unitNum").val(res.data.unitNum)
				  $("#unitCode").val(res.data.unitCode)
				  $("#productData").val(res.data.productData.substr(0,10))
				  $("#takenOffStatus").val(res.data.takenOffStatus)
				  $("#tray").val(res.data.tray)
				  $("#taskPeo").val(res.data.taskPeo)
				  $("#positions").val(res.data.positions)
				  $("#takenStatus").val(res.data.takenStatus)
				  $("#result").val(res.data.result)
				  layui.form.render("select");
			  }
		  })
	  }

	  GetByiddatas()
	layui.use(['form', 'laydate'], function(){
	  var form = layui.form;
	  var layer = layui.layer;
	  var laydate = layui.laydate;

	  // 指定开关事件,生成车间编码
	  form.on('switch(switchTest)', function(data){
		  var dates=new Date();
		  var nums=dates.getFullYear()+(dates.getMonth()+1).toString().padStart(2,'0')+dates.getDate().toString().padStart(2,'0');
		  if(data.elem.checked){
			  var random=Math.floor(Math.random()*10)+'';
			  for(var i=0;i<2;i++){
				  random+=Math.floor(Math.random()*10);
			  }
			  random='SP'+nums+random;
			  $("#productCode").val(random);
		  }else{
			  $('input[name="productCode"]').val('');
		  }

	  });

	  // 提交事件
	  form.on('submit(demo1)', function(data){
		var field = data.field; // 获取表单字段值
		// 此处可执行 Ajax 等操作
		console.log(field)
		$.ajax({
			url:'/Puff/UpdateTakendatas',
		   data:field,
		   type:'post',
		   dataType:'json',
		   success:res=>{
			   if (res > 0) {
				  //layer信息提示
				  layer.alert('修改成功');//下面是关键代码
				  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
				  window.parent.location.reload(); // 刷新父页
				  parent.layer.close(index); //再执行关闭
				  setTimeout(function () { parent.layer.close(index) }, 30000);//延迟s
			   }
			   else {
				  layer.alert("修改失败！");
			   }
		   }
		})
		return false; // 阻止默认 form 跳转
	  });
	});
</script>

